package cn.kailangtu.myapplication;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.navigation.fragment.NavHostFragment;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import cn.kailangtu.myapplication.camera.AvcPlayerHelper;
import cn.kailangtu.myapplication.databinding.FragmentSecondBinding;
import cn.kailangtu.myapplication.events.SerialData;
import cn.kailangtu.myapplication.fragment.BaseFragment;
import cn.kailangtu.myapplication.tools.APPSPUtils;
import cn.kailangtu.myapplication.tools.MediaPlayerUtils;

public class SecondFragment extends BaseFragment {

    private FragmentSecondBinding binding;




    @Override
    public View onCreateView(
            LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState
    ) {
        binding = FragmentSecondBinding.inflate(inflater, container, false);
        return binding.getRoot();


    }


    AvcPlayerHelper avcPlayerHelper = new AvcPlayerHelper();
    public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        binding.buttonSet1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                NavHostFragment.findNavController(SecondFragment.this)
                        .navigate(R.id.action_SecondFragment_to_FirstFragment);
            }
        });
        MediaPlayerUtils.getInstance().playZhuanxiangEnd();


       String url =   "rtsp://192.168.1.29:554/user=admin_password=tlJwpbo6_channel=1_stream=0.sdp?real_stream";

        avcPlayerHelper.initIPCameraView(binding.apRealView,url,this.getActivity());
    }
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(SerialData event){
        if(event.getAtime()!=null) {
            binding.TextViewTime.setText(event.getAtime());
        }
        // data=event.getA1();
        // Log.e("rrrrrrrr","uuuu"+data[0]);
    }



    //EventBus  推出
    @Override
    public void onStop(){
        super.onStop();
        EventBus.getDefault().unregister(this);
        avcPlayerHelper.close();
    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }

}